//## begin module%3B8DA80201A0.cm preserve=no
//	  %X% %Q% %Z% %W%
//## end module%3B8DA80201A0.cm

//## begin module%3B8DA80201A0.cp preserve=no
//	+----------------------------------------------+
//	| SVMBR - A program for training SVMs          |
//	+----------------------------------------------+
//	| * Creator, modeling, coding:                 |
//	|    Marcelo Barros de Almeida                 |
//	|    barros@smar.com.br                        |
//	|    http://litc.cpdee.ufmg.br/~barros/        |
//	| * Coding, improvements, bug fixes:           |
//	|    Bernardo Penna                            |
//	|    bprc@brfree.com.br                        |
//	+----------------------------------------------+
//
//	 Copyright(c) 2002 by Marcelo Barros de Almeida
//	                            All rights reserved
//
//	-[CVS]------------------------------------------
//	$Author$
//	$Date$
//	$Source$
//	$Name$
//	$Revision$
//	------------------------------------------------
//## end module%3B8DA80201A0.cp

//## Module: subset%3B8DA80201A0; Package body
//## Subsystem: <Top Level>
//## Source file: D:\textotese\svmbr\src\subset.cpp

//## begin module%3B8DA80201A0.additionalIncludes preserve=no
//## end module%3B8DA80201A0.additionalIncludes

//## begin module%3B8DA80201A0.includes preserve=yes
//## end module%3B8DA80201A0.includes

// subset
#include "subset.h"
//## begin module%3B8DA80201A0.declarations preserve=no
//## end module%3B8DA80201A0.declarations

//## begin module%3B8DA80201A0.additionalDeclarations preserve=yes
//## end module%3B8DA80201A0.additionalDeclarations


// Class SubSet 





SubSet::SubSet()
  //## begin SubSet::SubSet%.hasinit preserve=no
  //## end SubSet::SubSet%.hasinit
  //## begin SubSet::SubSet%.initialization preserve=yes
  //## end SubSet::SubSet%.initialization
{
  //## begin SubSet::SubSet%.body preserve=yes
  //## end SubSet::SubSet%.body
}

SubSet::SubSet (INT sz)
  //## begin SubSet::SubSet%999139392.hasinit preserve=no
  //## end SubSet::SubSet%999139392.hasinit
  //## begin SubSet::SubSet%999139392.initialization preserve=yes
  //## end SubSet::SubSet%999139392.initialization
{
  //## begin SubSet::SubSet%999139392.body preserve=yes
	init(sz);
  //## end SubSet::SubSet%999139392.body
}


SubSet::~SubSet()
{
  //## begin SubSet::~SubSet%.body preserve=yes
	delete hashTable;
	delete set;
  //## end SubSet::~SubSet%.body
}



//## Other Operations (implementation)
INT SubSet::add (INT i1)
{
  //## begin SubSet::add%999139388.body preserve=yes

	hashTable[i1] = top;
	set[top++] = i1;

	return hashTable[i1];

  //## end SubSet::add%999139388.body
}

INT SubSet::remove (INT i1)
{
  //## begin SubSet::remove%999139389.body preserve=yes

	if(hashTable[i1] == -1){
		cerr << "Error: removing invalid index (SubSet::remove)" << endl;
		exit(1);
	}

	INT h1 = hashTable[i1];

	set[h1] = set[--top];
	hashTable[set[top]] = h1;
	hashTable[i1] = EMPTY;
	set[top] = -1; /* only to keep consistency with initialization */

	return h1;

  //## end SubSet::remove%999139389.body
}

VOID SubSet::init (INT sz)
{
  //## begin SubSet::init%999139390.body preserve=yes
	maxSize = sz;
	try{
		hashTable = new INT [maxSize];
		set = new INT [maxSize];
	} 
	catch(...){
		cerr << "Error when allocating memory.(SubSet::init)" << endl;
		exit(1);
	}

	for(INT i = 0 ; i < maxSize ; i++){
		hashTable[i] = EMPTY;
		set[i] = EMPTY;
	}
	top = 0;
  //## end SubSet::init%999139390.body
}

INT SubSet::getSize ()
{
  //## begin SubSet::getSize%999139391.body preserve=yes
	return top;
  //## end SubSet::getSize%999139391.body
}

VOID SubSet::dump ()
{
  //## begin SubSet::dump%1013528662.body preserve=yes
	printf("\nVEC\tHT \tSET\n");
	for(INT i = 0 ; i < maxSize ; i++) {
		printf("%03d\t%03d\t%03d\n",(int)i,(int)hashTable[i],(int)set[i]);
	}
  //## end SubSet::dump%1013528662.body
}

// Additional Declarations
  //## begin SubSet%3B8DA6FC02BC.declarations preserve=yes
  //## end SubSet%3B8DA6FC02BC.declarations

//## begin module%3B8DA80201A0.epilog preserve=yes
//## end module%3B8DA80201A0.epilog
